// src/features/workspaces/api/use-get-workspace-info.ts
import {MARK_DATA_URL} from "@/lib/social/constants";
import {useCurrentUser} from "@/hooks/use-current-user";

interface Props {
    id: string
}

export const useGetWorkspaceInfo = async ({id}: Props) => {
    const user = useCurrentUser()
    // const res = await fetch(`${MARK_DATA_URL}/workspaces/${id}`)
    const res = await fetch(`/api/workspaces/${id}`)
    const data = await res.json()

    // todo get cur user
    // const m_res = await fetch(`${MARK_DATA_URL}/members?workspaceId=${id}&userId=${'123456'}`)
    const m_res = await fetch(`/api/members?workspaceId=${id}&userId=${user?.id!}`)
    const members = await m_res.json()

    const isLoading = data === undefined || members === undefined

    return {data: {name: data.name, isMember: members && members.length !== 0}, isLoading}
}